package javaapplication1;

import java.util.Random;

/**
 * User: VU MINH KHOI
 * Date: April 4, 2011
 * CP1300 Assignment 1
 */
public class Vehicle {
    private int xPos;
    private int yPos;
    private boolean isOnHLane;
    private boolean isJustOvertake=false;
    private int SPEED;

    public Vehicle(){};

    public Vehicle(int size, boolean isOnHLane, int VLanes, int HLanes, int speed) {
        this.isOnHLane = isOnHLane;
        this.SPEED = speed;

        //random starting position
        Random gernerator = new Random();
        if(isOnHLane){
            int randPos = gernerator.nextInt(HLanes);
            this.startOnHLanes(size/2+randPos);            
        }
        else{
            int randPos = gernerator.nextInt(VLanes);
            this.startOnVLanes(size/2+randPos);
        }
    }

    private void startOnHLanes(int startPos) {
        this.xPos = 0;
        this.yPos = startPos;
    }

    private void startOnVLanes(int startPos) {
        this.yPos = 0;
        this.xPos = startPos;
    }

    public int getxPos() {
        return xPos;
    }

    public void setxPos(int xPos) {
        this.xPos = xPos;
    }

    public int getyPos() {
        return yPos;
    }

    public void setyPos(int yPos) {
        this.yPos = yPos;
    }

    public boolean isIsOnHLane() {
        return isOnHLane;
    }

    public void setIsOnHLane(boolean isOnHLane) {
        this.isOnHLane = isOnHLane;
    }

    public void move(double velocity) {
        if(this.isOnHLane){
            if(isJustOvertake){
                this.yPos++;
                this.isJustOvertake=false;
            }
            this.xPos += SPEED*velocity;
        }
        else{
            if(isJustOvertake){
                this.xPos++;
                this.isJustOvertake=false;
            }
            this.yPos += SPEED*velocity;
        }
    }

    void overtake() {
        //if this car is running on horizontal lane, overtake to the North.
        if(this.isOnHLane)
            this.yPos--;

        //if this car is running on vertical lane, overtake to the West.
        if(!this.isOnHLane)
            this.xPos--;

        this.isJustOvertake=true;
    }

    public String getShape(){
        return "";
    }
}
